/*
 * ZCL Global Command
 * */

#ifndef  _ZCL_COMMAND_H_
#define  _ZCL_COMMAND_H_

/*
 *    Macro
 * */
#define ZCL_MAX_PARAM_LENGTH      (SL_ZIGBEE_AF_MAXIMUM_APS_PAYLOAD_LENGTH - 5)
#define ZCL_ATTR_ID_MAX           0xFFFF


/*
 * Typedef
 * */
typedef uint16_t  zclReadAttr_t;

typedef __PACKED_STRUCT
{
  uint16_t attrId;
  uint8_t status;
  uint8_t dataType;
  uint8_t dataSize;
  uint8_t *dataPtr;
}zclReadRsp_t;

typedef __PACKED_STRUCT
{
  uint16_t attrId;
  uint8_t dataType;
  uint8_t dataSize;
  uint8_t *dataPtr;
}zclWriteAttr_t;

typedef __PACKED_STRUCT
{
  uint16_t attrId;
  uint8_t status;
}zclWriteRsp_t;

typedef __PACKED_STRUCT
{
  uint8_t  direction;
  uint16_t attrId;
  uint8_t  dataType;
  uint16_t minReportInt;
  uint16_t maxReportInt;
  uint8_t *changeValue;
  uint16_t timeout;
}zclCfgReport_t;

typedef __PACKED_STRUCT
{
  uint8_t  status;
  uint8_t  direction;
  uint16_t attrId;
}zclCfgReportRsp_t;

typedef __PACKED_STRUCT
{
  uint8_t  direction;
  uint16_t attrId;
}zclReadReport_t;

typedef __PACKED_STRUCT
{
  uint8_t  status;
  uint8_t  direction;
  uint16_t attrId;
  uint8_t  dataType;
  uint16_t minReportInt;
  uint16_t maxReportInt;
  uint8_t *changeValue;
  uint16_t timeout;
}zclReadReportRsp_t;

typedef __PACKED_STRUCT
{
  uint16_t attrId;
  uint8_t dataType;
  uint8_t dataSize;
  uint8_t *dataPtr;
}zclReportAttr_t;

typedef __PACKED_STRUCT
{
  uint16_t attrId;
  uint8_t  dataType;
}zclDiscAttrRsp_t;

typedef __PACKED_STRUCT
{
  uint16_t attrId;
  uint8_t  dataType;
  uint8_t  access;
}zclDiscAttrExtRsp_t;

uint16_t zcl_read_attributes_fill_buffer(uint16_t clusterId,
                                         uint16_t manufacturerCode,
                                         uint8_t sequence,
                                         uint8_t direction,
                                         uint8_t num,
                                         zclReadAttr_t *attrs);
uint8_t zcl_read_attributes_response_parse(uint8_t *buf, zclReadRsp_t *attrs);

uint16_t zcl_write_attributes_fill_buffer(uint16_t clusterId,
                                          uint16_t manufacturerCode,
                                          uint8_t sequence,
                                          uint8_t direction,
                                          uint8_t num,
                                          zclWriteAttr_t *attrs);
uint8_t zcl_write_attributes_response_parse(uint8_t *buf, zclWriteRsp_t *attrs);

uint16_t zcl_configure_reporting_fill_buffer(uint16_t clusterId,
                                             uint16_t manufacturerCode,
                                             uint8_t sequence,
                                             uint8_t direction,
                                             uint8_t num,
                                             zclCfgReport_t *attrs);
uint8_t zclConfigureReportingResponseParse(uint8_t *buf, zclCfgReportRsp_t *attrs);

uint16_t zcl_read_reporting_configuration_fill_buffer(uint16_t clusterId,
                                                      uint16_t manufacturerCode,
                                                      uint8_t sequence,
                                                      uint8_t direction,
                                                      uint8_t num,
                                                      zclReadReport_t *attrs);
uint8_t zcl_read_reporting_configuration_response_parse(uint8_t *buf, zclReadReportRsp_t *attrs);

uint8_t zcl_report_attributes_parse(uint8_t *buf, zclReportAttr_t *attrs);

uint16_t zcl_discover_attributes_fill_buffer(uint16_t clusterId,
                                             uint16_t manufacturerCode,
                                             uint8_t sequence,
                                             uint8_t direction,
                                             bool extend,
                                             uint8_t num,
                                             uint16_t startAttrId);
uint8_t zcl_discover_attributes_response_parse(uint8_t *buf, zclDiscAttrRsp_t* attrs);
uint8_t zcl_discover_attributes_extend_response_parse(uint8_t *buf, zclDiscAttrExtRsp_t* attrs);

#endif
